package app.util.image.action.morph
{
	import app.util.*;
	import app.util.image.*;
	import app.util.image.action.*;
	import app.util.image.calc.*;
	
	import flash.display.*;

	public class MorphSmoothingAction extends SEBasedAction
	{
		private var progress:Number = 0;
		private var ret:GrayBitmapData;
		
		public override function getDescription():String
		{
			return "Morphological Smoothing";
		}
		
		protected override function getFinalBitmapData():BitmapData
		{
			return this.ret.toBitmapData();
		}
		
		protected override function processBitmapDataByStep():Number
		{
			if(this.progress == 0)
			{
				var src:BitmapData = Mediator.getCurrentBitmapData();
				var gSrc:GrayBitmapData = MorphUtility.autoGray(src);
				this.ret = MorphUtility.doGrayDilation(gSrc, se);
			}
			else if(this.progress == 0.25)
			{
				this.ret = MorphUtility.doGrayErosion(this.ret, se);
			}
			else if(this.progress == 0.5)
			{
				this.ret = MorphUtility.doGrayErosion(this.ret, se);
			}
			else
			{
				this.ret = MorphUtility.doGrayDilation(this.ret, se);
			}
			
			this.progress += 0.25;
			return this.progress;
		}
	}
}